package anatex.kea.kea;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeMap;

public class AttributesDiscretizer {

	ArrayList<CandidatePhrase> candidatePhrases;
	ArrayList<String> phrases;
	ValueComparator comparator;
	
	public AttributesDiscretizer(ArrayList<CandidatePhrase> cp) {
		setCandidatePhrases(cp);
		
		comparator = new ValueComparator(new TreeMap());
	}
	
	public void setCandidatePhrases(ArrayList<CandidatePhrase> cp) {
		candidatePhrases = cp;
	}
	
	protected void discretizeAttribute(String attr) {
		TreeMap<Integer, Double> values = new TreeMap<Integer, Double>(comparator);
		comparator.setBase(values);
		
		for (int i = 0; i < candidatePhrases.size(); i ++) {
			values.put(i, candidatePhrases.get(i).get(attr));
		}
		
		/**
		 * TODO - да се добави информация в candidatePhrase за оригиналната дума и дали тя е определена 
		 * като ключова дума или не от GenEx
		 */
	}
	
	public void discretize() {
		String[] attributes = {CandidatePhrase.TDxIDF, CandidatePhrase.DISTANCE};
		
		for (int i = 0; i < attributes.length; i ++) {
			String attr = attributes[i];
			
			discretizeAttribute(attr);
		}
	}
	
}

class ValueComparator implements Comparator {

	TreeMap base;
	public ValueComparator(TreeMap base) {
		this.base = base;
	}
	
	public void setBase(TreeMap b) {
		base = b;
	}
	
	public int compare(Object a, Object b) {
		if((Double)base.get(a) > (Double)base.get(b)) {
			return 1;
		} else if((Double)base.get(a) == (Double)base.get(b)) {
			return 0;
		} else {
			return -1;
		}
	}
}
